Skip to content

[orion-server]: auto targets generation for buck2#1312

Merged
benjamin-747 merged 3 commits into
gitmono-dev:mainfrom
Ivanbeethoven:main
Aug 7, 2025
Merged

[orion-server]: auto targets generation for buck2#1312
benjamin-747 merged 3 commits into
gitmono-dev:mainfrom
Ivanbeethoven:main

Conversation

@Ivanbeethoven

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Xiaoyang Han <lux1an@qq.com>
@vercel

vercel Bot commented Aug 6, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mega ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 6, 2025 3:34pm

This comment was marked as outdated.

@genedna
genedna requested review from benjamin-747 and Copilot August 6, 2025 09:14

This comment was marked as outdated.

@genedna
genedna requested a review from Copilot August 6, 2025 14:00

This comment was marked as outdated.

Signed-off-by: Han Xiaoyang <lux1an@qq.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds automatic target generation for buck2 builds by downloading BUCK and .buckconfig files from a blob API and executing buck2 commands to determine build targets dynamically.

  • Introduces a new buck2 module with functionality to download build configuration files and execute buck2 commands
  • Modifies the build request API to accept hash values for BUCK and .buckconfig files instead of hardcoded targets
  • Adds retry logic for file downloads and proper error handling throughout the buck2 workflow

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
orion-server/src/main.rs Adds buck2 module import
orion-server/src/buck2.rs New module implementing buck2 file download and target generation functionality
orion-server/src/api.rs Updates BuildRequest struct and task_handler to use dynamic target generation
orion-server/Cargo.toml Adds dependencies for tokio-retry and reqwest
orion-server/.env Adds MONOBASE_URL environment variable
Comments suppressed due to low confidence (1)

Comment thread orion-server/src/buck2.rs
let last_line = get_buck2_targets_last_line(&tmp_dir_path)?;

// Clean up the temporary directory after getting the result
//TODO: Cleanup should happen in a finally block or using RAII to ensure temporary files are removed even if buck2 command fails. Consider using a guard or defer pattern. TempDirGuard , for example.

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO comment identifies a legitimate issue. The current cleanup logic can fail to execute if the buck2 command panics or if there's an early return. Consider implementing a proper RAII guard using a struct with Drop trait or using the tempfile crate's TempDir.

Copilot uses AI. Check for mistakes.
Comment thread orion-server/src/api.rs
pub struct BuildRequest {
repo: String,
target: String,
buck_hash: String,

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The field name 'buck_hash' is ambiguous. Consider renaming to 'buck_file_hash' or 'buck_build_file_hash' to clearly indicate this is the hash for the BUCK build file.

Suggested change
buck_hash: String,
#[serde(rename = "buck_hash")]
buck_file_hash: String,

Copilot uses AI. Check for mistakes.
Comment thread orion-server/src/api.rs
Comment on lines +287 to +296
// Download and get buck2 targets first
let target = match download_and_get_buck2_targets(&req.buck_hash, &req.buckconfig_hash).await {
Ok(target) => target,
Err(e) => {
tracing::error!("Failed to download buck2 targets: {}", e);
return (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "message": format!("Failed to download buck2 targets: {}", e) })),
).into_response();
}

Copilot AI Aug 6, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The buck2 target generation happens synchronously in the request handler, which could cause request timeouts for large projects. Consider moving this to an async background task or implementing a timeout mechanism.

Suggested change
// Download and get buck2 targets first
let target = match download_and_get_buck2_targets(&req.buck_hash, &req.buckconfig_hash).await {
Ok(target) => target,
Err(e) => {
tracing::error!("Failed to download buck2 targets: {}", e);
return (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "message": format!("Failed to download buck2 targets: {}", e) })),
).into_response();
}
// Download and get buck2 targets first, with a timeout
let buck2_timeout = Duration::from_secs(30);
let target = match timeout(
buck2_timeout,
download_and_get_buck2_targets(&req.buck_hash, &req.buckconfig_hash)
).await {
Ok(Ok(target)) => target,
Ok(Err(e)) => {
tracing::error!("Failed to download buck2 targets: {}", e);
return (
StatusCode::INTERNAL_SERVER_ERROR,
Json(serde_json::json!({ "message": format!("Failed to download buck2 targets: {}", e) })),
).into_response();
}
Err(_) => {
tracing::error!("Timeout while downloading buck2 targets");
return (
StatusCode::REQUEST_TIMEOUT,
Json(serde_json::json!({ "message": "Timeout while downloading buck2 targets" })),
).into_response();
}

Copilot uses AI. Check for mistakes.
@benjamin-747
benjamin-747 added this pull request to the merge queue Aug 7, 2025
Merged via the queue into gitmono-dev:main with commit 444c8c1 Aug 7, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants